package com.testdemo.web.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.testdemo.web.dao.LabDao;
import com.testdemo.web.vo.LabInfo;

@Service
public class LabServiceImpl implements LabService{

	@Autowired
	private LabDao labDao;
	
	
	
	/* (non-Javadoc)
	 * @see com.testdemo.web.service.LabService#getLabTypeList()
	 */
	public List<LabInfo> getLabTypeList() {
		return labDao.selectLabType();
	}
	

	public boolean checkuserName(String username, int labid) {
		String labusername = labDao.selectLabUserNameByLabid(labid);
		if(labusername.equals(username)) return true;
		return false;
	}


	@Override
	public LabInfo selectLabinfoById(int labid) {
		
		return labDao.selectLabById(labid);
	}


	@Override
	public int updateLabinfo(LabInfo labInfo) {
		LabInfo orginLabinfo = selectLabinfoById(labInfo.getLabid().intValue());
		//比较更新的字段
		if(labInfo.getLabname() == null) labInfo.setLabname(orginLabinfo.getLabname());
		if(labInfo.getAddress() == null) labInfo.setAddress(orginLabinfo.getAddress());
		if(labInfo.getOpen() == null) labInfo.setOpen(orginLabinfo.getOpen());
		return labDao.updateLabinfo(labInfo);
	}
}
